home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / LISTMANA / __TESTER / TEXTEDIT.C < prev    next >
Text File  |  1989-06-25  |  6KB  |  254 lines

  1. /****                                                                    */
  2. /****    List Testing Code version 1.0 (beta)                            */
  3. /****                                                                    */
  4. /****    All portions of this source code are the property of Jack        */
  5. /****    Herrington.  I, Jack Herrington, give you permission to use        */
  6. /****    use or alter the code in any way that pleases you.  You must    */
  7. /****    however return by whatever means avaliable any improvements        */
  8. /****    you believe significant to Jack Herrington, accepting that        */
  9. /****    these improvements might be contained in later releases of        */
  10. /****    the code. I also grant you permission to remove this header        */
  11. /****    from any file you are WORKING on, as long as you put it back    */
  12. /****    when you're stopped WORKING on it.                                */
  13. /****                                                                    */
  14. /****    Jack Herrington: University Of Miami, Biomedical Computing        */
  15. /****                     1600 N.W. 10th Ave. (R-53)                        */
  16. /****                     (305) 547-6538                                    */
  17. /****                                                                    */
  18.  
  19. /****/
  20. /**** TextEdit List Handler */
  21. /****/
  22.  
  23. #include "ListManager.h"
  24. #include "Tester.h"
  25. #include "TextEditList.h"
  26.  
  27. /****/
  28. /**** TextEdit List main dispersion routine */
  29. /****/
  30.  
  31. void TextEditListHandler(mess,data)
  32. int mess;
  33. unsigned char *data;
  34. {
  35.     switch(mess)
  36.     {
  37.     case MESS_NEW: TextEditListHandlerNew(); break;
  38.     case MESS_HIT: TextEditListHandlerHit((int *)data); break;
  39.     case MESS_CLOSE: TextEditListHandlerClose(); break;
  40.     case MESS_ACTIVATE: TextEditListHandlerActivate(1); break;
  41.     case MESS_DEACTIVATE: TextEditListHandlerActivate(0); break;
  42.     }
  43. }
  44.  
  45. /****/
  46. /**** Respond to a new message */
  47. /****/
  48.  
  49. void TextEditListHandlerNew()
  50. {
  51.     TextEditWindowInfo *tewi;
  52.  
  53.         /**** Create the dialog */
  54.  
  55.     if ( TesterDialogNew(1002,CurHandler) == (-1) ) return;
  56.     SetPort(Windows[CurWindow].window);
  57.  
  58.         /**** Allocate the window record */
  59.  
  60.     TesterAllocateWindowData((long)sizeof(TextEditWindowInfo));
  61.     TesterLockWindowInfo();
  62.     tewi = (TextEditWindowInfo *)TesterGetWindowInfo();
  63.  
  64.         /**** Setup the window */
  65.  
  66.     TextEditListHandlerSetupList(tewi);
  67.  
  68.         /**** Unlock the window information and leave */
  69.  
  70.     TesterUnLockWindowInfo();
  71. }
  72.  
  73. /****/
  74. /**** Setup the list */
  75. /****/
  76.  
  77. void TextEditListHandlerSetupList(tewi)
  78. TextEditWindowInfo *tewi;
  79. {
  80.     TextStyle style;
  81.     Handle item;
  82.     Point cellSize,cell;
  83.     Rect box,dBox;
  84.     char charTmp[255];
  85.     int type,y,width;
  86.  
  87.         /**** Get the box for the list */
  88.  
  89.     GetDItem(Windows[CurWindow].window,ListBox,&type,&item,&box);
  90.     SetDItem(Windows[CurWindow].window,ListBox,type,TextEditListHandlerUpdate,&box);
  91.  
  92.         /**** Create the data bounds */
  93.  
  94.     dBox.left = 0; dBox.right = MAX_X;
  95.     dBox.top = 0; dBox.bottom = MAX_Y;
  96.     cellSize.h = 80; cellSize.v = 15;
  97.  
  98.         /**** Create the list */
  99.  
  100.     tewi->nlh = ListNew(&box,&dBox,cellSize,0,
  101.         Windows[CurWindow].window,0,0,0,1);
  102.  
  103.         /**** Setup global cell definitions */
  104.  
  105.     ListSetFrameWidth(1,15,tewi->nlh);
  106.     ListSetFrameDrawer(TextEditListHandlerDrawFrame,tewi->nlh);
  107.  
  108.     ListSetGlobalBox(ListBottom,tewi->nlh);
  109.     ListSetGlobalFont(times,12,0,tewi->nlh);
  110.     ListSetScrollMethod(incMethod,tewi->nlh);
  111.  
  112.     ListSetColumnWidth(0,(box.right-box.left)-17,tewi->nlh);
  113.     ListSetAddative(-1,-1,tewi->nlh);
  114.  
  115.         /**** Set the cells */
  116.  
  117.     style.tsFont = times;
  118.     style.tsSize = 12;
  119.     style.tsFace = 0;
  120.  
  121.     cell.h = 0;
  122.     for(y=0;y<MAX_Y;y++)
  123.     {
  124.         (void)sprintf(charTmp,BigString[y]);
  125.  
  126.         tewi->text[y] = TEStylNew(&box,&box);
  127.         TESetText(charTmp,(long)strlen(charTmp),tewi->text[y]);
  128.         TESetSelect(0L,6000L,tewi->text[y]);
  129.         TESetStyle((doFont|doFace|doSize),&style,FALSE,tewi->text[y]);
  130.  
  131.         cell.v = y;
  132.         cell.h = 0;
  133.         ListSetHandler(TEUpdateHandler,cell,tewi->nlh);
  134.         ListSetData((Handle)tewi->text[y],cell,tewi->nlh);
  135.         width = ListCalTextWidth(cell,tewi->nlh) + 5;
  136.         ListSetRowWidth(cell.v,width,tewi->nlh);
  137.     }
  138.  
  139.         /**** Setup the flags */
  140.  
  141.     ListSetEhancedFlags((NoTrackOutside),tewi->nlh);
  142.     ListDoDraw(TRUE,tewi->nlh);
  143. }
  144.  
  145. /****/
  146. /**** Draw the list */
  147. /****/
  148.  
  149. pascal void TextEditListHandlerUpdate(Window,ItemNumber)
  150. WindowPtr Window;
  151. int ItemNumber;
  152. {
  153.     TextEditWindowInfo *tewi;
  154.  
  155.         /**** Lock the window information and update */
  156.  
  157.     SetPort(Window);
  158.     TesterLockWindowInfoWindow(Window);
  159.     tewi = (TextEditWindowInfo *)TesterGetWindowInfoIndirect(Window);
  160.         ListUpdateWhole(tewi->nlh);
  161.     TesterUnLockWindowInfoWindow(Window);
  162. }
  163.  
  164. /****/
  165. /**** Hit in the window */
  166. /****/
  167.  
  168. void TextEditListHandlerHit(hit)
  169. int *hit;
  170. {
  171.     TextEditWindowInfo *tewi;
  172.     Point cell,lpt;
  173.     Rect sizeArea;
  174.     int part;
  175.  
  176.         /**** Lock the window information */
  177.  
  178.     TesterLockWindowInfo();
  179.     tewi = (TextEditWindowInfo *)TesterGetWindowInfo();
  180.     SetPort(Windows[CurWindow].window);
  181.  
  182.         /**** Disperse according to dialog hit */
  183.  
  184.     if ( *hit == ListBox )
  185.     {
  186.         GetMouse(&lpt);
  187.         part = ListPart(lpt,&cell,tewi->nlh);
  188.         switch(part)
  189.         {
  190.         case inHorizScroll:
  191.         case inVertScroll:
  192.          case inCell:
  193.             ListCickEnhanced(lpt,0,tewi->nlh,ListSingleDrag);
  194.             break;
  195.          }
  196.     }
  197.  
  198.         /**** Unlock the window information */
  199.  
  200.     TesterUnLockWindowInfo();
  201. }
  202.  
  203. /****/
  204. /**** Activate or DeActivate the list */
  205. /****/
  206.  
  207. void TextEditListHandlerActivate(act)
  208. int act;
  209. {
  210.     TextEditWindowInfo *tewi;
  211.  
  212.     TesterLockWindowInfo();
  213.     tewi = (TextEditWindowInfo *)TesterGetWindowInfo();
  214.         ListActivate(act,tewi->nlh);
  215.     TesterUnLockWindowInfo();
  216. }
  217.  
  218. /****/
  219. /**** Draw the frame title */
  220. /****/
  221.  
  222. void TextEditListHandlerDrawFrame(message,visBox,cell)
  223. int message;
  224. Rect *visBox;
  225. int cell;
  226. {
  227.     char charTmp[255];
  228.     int width;
  229.  
  230.         /**** Draw the message into the frame */
  231.  
  232.     if ( message == HorizCell )
  233.     {
  234.         width = StringWidth(ColumnTitle) + 5;
  235.         MoveTo(visBox->right-width,visBox->bottom-2);
  236.         DrawString(ColumnTitle);
  237.     }
  238. }
  239.  
  240. /****/
  241. /**** Close up the window */
  242. /****/
  243.  
  244. void TextEditListHandlerClose()
  245. {
  246.     TextEditWindowInfo *tewi;
  247.  
  248.     TesterLockWindowInfo();
  249.     tewi = (TextEditWindowInfo *)TesterGetWindowInfo();
  250.         ListDispose(tewi->nlh);
  251.     TesterUnLockWindowInfo();
  252.  
  253.     TesterKillWindow(CurWindow);
  254. }